<template>
	<div class="customer">
		<div>
			<label>{{ $t('route.Device') }}</label>
			<div></div>
			<button><img /><label>{{ $t('route.Customer') }}</label></button>
		</div>


		<div>
			<div>
				<div class="div-handle-right">
					<el-button @click='jumpPage(0)'>{{ $t('route.Add') }}</el-button>
					<el-button @click="searchClick">{{ $t('route.search') }}</el-button>
					<input v-model="query.search" placeholder="" />
				</div>
			</div>

			<el-table class="table" :data="customerList" style="width: 100%">
				<el-table-column type="selection" width="55" />
				<el-table-column prop="number" :label="$t('route.ID')" />
				<el-table-column prop="name" :label="$t('route.designation')" />
				<el-table-column prop="address" :label="$t('route.address')" />
				<el-table-column prop="region" :label="$t('route.Area')" />
				<el-table-column prop="contactName" :label="$t('route.Contact_Name')" />
				<el-table-column prop="contactMobile" :label="$t('route.Telephone')" />
				<el-table-column :label="$t('route.Add_date')">
					<template #default="scope">
						{{ new Date(scope.row.gmtCreate).format('yyyy-MM-dd') }}
					</template>
				</el-table-column>
				<el-table-column :label="$t('route.operate')" width="240">
					<template #default="scope">
						<el-button type="text">{{ $t('route.Editing') }}</el-button>
						<el-button type="text" @click="batchSNClick(scope.row)">{{ $t('route.Batch_SN') }}</el-button>
						<el-button type="text" style="color:red" @click="deleteClick(scope.row)">
							{{ $t('route.Delete') }}</el-button>
						<el-button type="text" @click="agentClick(scope.row)">{{ $t('route.agent') }}</el-button>
					</template>
				</el-table-column>
			</el-table>
			<div class="pagination">
				<el-pagination style="float: right;" background @current-change="handlePageChange"
					:current-page="query.pageNum" :page-size="query.pageSize" layout="total, prev, pager, next"
					:total="query.total"></el-pagination>
			</div>

		</div>

		<!-- 编辑弹出框 -->
		<el-dialog :title="$t('route.oBatch_generated_sequence_numberperate')" v-model="dialogVisible">
			<el-form label-position="right" label-width="120px">
				<el-form-item :label="$t('route.amount')">
					<el-input-number v-model="serialNumCount" :min="1" :max="10000" />
				</el-form-item>
				<el-form-item>
					<el-button @click='addClick'>{{ $t('route.Add') }}</el-button>
				</el-form-item>
			</el-form>
		</el-dialog>

	</div>
</template>

<script>
import http from "../../js/http/http.js";
import api from "../../js/http/api.js";
export default {
	data() {
		return {
			query: {
				pageNum: 1,
				pageSize: 10,
				total: 0,
				search: null,
			},
			customerList: [],
			selCustomer: null,
			dialogVisible: false,
			serialNumCount: 1
		};
	},
	methods: {
		batchSNClick(item) {
			this.selCustomer = item;
			this.dialogVisible = true;
		},
		addClick() {
			http.post(api.CREATE_SN_BATCH, {
				count: this.serialNumCount,
				adminId: this.selCustomer.id
			}, data => {
				this.$message.success(this.$t('route.Build_succeeded'));
				this.dialogVisible = false;
				this.$router.push("/admin/serial-num");
			});
		},
		handlePageChange(pageNum) {
			this.query.pageNum = pageNum;
			this.getCustomerList();
		},
		jumpPage(type) {
			if (type == 0) {
				this.$router.push("/admin/add-customer");
			}
		},
		searchClick() {
			this.query.pageNum = 1;
			this.getCustomerList();
		},
		getCustomerList() {
			http.post(
				api.GET_CUSTOMER_LIST, {
				pageNum: this.query.pageNum,
				pageSize: this.query.pageSize,
				search: this.query.search,
				adminId: this.$store.state.user.id,
			},
				data => {
					this.customerList = data.data.customerList;
					this.query.total = data.data.total;

				}
			);
		}
	},
	created() {
		this.getCustomerList();
	},
};
</script>
<style lang="scss" scoped>
.customer {
	color: #444444;
	font-size: 18px;
	padding-right: 20px;
	height: calc(100vh - 100px);
	// overflow: scroll;
	scrollbar-width: none;
	/* firefox */
	-ms-overflow-style: none;
	/* IE 10+ */
	overflow-x: hidden;
	overflow-y: auto;

	>div:nth-of-type(1) {
		display: flex;
		flex-direction: row;
		align-items: center;
		margin-top: 20px;
		background-color: #ffffff;
		padding: 20px;
		border-radius: 5px;

		>label:nth-of-type(1) {
			font-weight: 600;
		}

		>div:nth-of-type(1) {
			width: 1px;
			background-color: #cccccc;
			height: 15px;
			margin: 0px 20px;
		}

		>button:nth-of-type(1) {
			background-image: url(../../assets/img/customer-1.png);
			background-repeat: no-repeat;
			background-size: 100% 100%;
			padding: 5px 10px;
			border: 0px;
			display: flex;
			color: #ffffff;
			flex-direction: row;
			align-items: center;
			font-weight: 800;

			>img {
				margin-right: 7px;
				width: 15px;
				height: 15px;
				content: url(../../assets/img/customer-2.png);
			}
		}
	}

	>div:nth-of-type(2) {
		display: flex;
		flex-direction: column;
		margin-top: 20px;
		background-color: #ffffff;
		padding: 20px;
		border-radius: 5px;


		>div:nth-of-type(1) {
			display: flex;
			flex-direction: row;
			align-items: center;

			.div-handle-right {
				flex: 1;
				flex-direction: row-reverse;
				text-align: right;
				display: flex;
				align-items: center;

				>input:nth-of-type(1) {
					border: 1px solid #eeeeee;
					font-size: 15px;
					width: 200px;
					padding: 5px 8px;
					outline: none;
				}

				>button {
					color: #A866FF;
					margin-left: 10px;
					padding: 4px 20px;
				}
			}
		}

		.table {
			margin-top: 20px;
		}

	}

	.select {
		width: 120px;
		margin-top: 10px;
	}

	.echart {
		height: 150px;
		width: 100%;
	}

	.input {
		width: 250px;
	}


}
</style>
